﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ADO.NET_Entity_Framework
{
    /// <summary>
    /// 2. Create a DAO class with static methods which provide functionality 
    /// for inserting, modifying and deleting customers. Write a testing class.
    /// </summary>
    public static class CustomerUtils
    {
        public static void AddCustomer(Customer customer)
        {
            NorthwindEntities context = new NorthwindEntities();
            context.Customers.AddObject(customer);
            context.SaveChanges();
        }

        public static void ModifyCustomer(Customer customer)
        {
            NorthwindEntities context = new NorthwindEntities();
            context.Attach(customer);
            context.ObjectStateManager.ChangeObjectState(customer, System.Data.EntityState.Modified);
            context.Refresh(System.Data.Objects.RefreshMode.ClientWins, customer);
            context.SaveChanges();
        }

        public static void RemoveCustomer(Customer customer)
        {
            NorthwindEntities context = new NorthwindEntities();
            context.Customers.DeleteObject(customer);
            context.SaveChanges();
        }
    }
}
